/*****************************************************************************/
/**
 *	\file	book_room.cpp
 *	\author	Xavier
 *	\date	2023/05/07
 *	\version	1.0
 *	\brief	订房实现
 *	\note	Copyright (c) 2020-2030 南京理工大学
 *	\remarks	无
 ******************************************************************************/
#include "head.h"

void bookRoom(CMgr *mgrobj)
{
    assert(NULL != mgrobj);
    const int price1 = 150;
    const int price2 = 200;
    const int price3 = 300;
    const int price4 = 600;
    mgrobj->customer[mgrobj->i] = new Customer;
    int room_standard, day;
Again008:
    cout << "请您选择预定房间的标准:\n";
    cout << "1.单人间  150元/天\n2.双人间  200元/天\n3.标准间  300元/天\n4.总统套房  600元/天\n";
    room_standard = inputINT();
    if (room_standard < 1 || room_standard > 4)
    {
        cout << "输入错误，请重新输入！";
        goto Again008;
    }
    cout << "请输入预定天数\n";
    day = inputINT();
    mgrobj->customer[mgrobj->i]->set_day(day);
Again006:
    switch (room_standard)
    {
        int n;
    case 1:
        cout << "住房费用总共为: " << day * price1 << "元\n"; // 计算住房费用
        for (n = 0; n < 20; n++)
        { // 从第一个级别的房间中查找一个空闲的房间
            if (mgrobj->room[n].state == 0)
            { // state=0表示该住房没有被预定的
                cout << "预定成功★房间号码为: " << mgrobj->room[n].number << endl;
                mgrobj->room[n].state = 1;
                mgrobj->customer[mgrobj->i]->set_room_number(mgrobj->room[n].number);
                break;
            }
        }
        break;
    case 2:
        cout << "住房费用总共为: " << day * price2 << " 元\n";
        for (n = 20; n < 40; n++)
        {
            if (mgrobj->room[n].state == 0)
            {
                cout << "预定成功★房间号码为: " << mgrobj->room[n].number << endl;
                mgrobj->room[n].state = 1;
                mgrobj->customer[mgrobj->i]->set_room_number(mgrobj->room[n].number);
                break;
            }
        }
        break;
    case 3:
        cout << "住房费用总共为: " << day * price3 << " 元\n";
        for (n = 40; n < 60; n++)
        {
            if (mgrobj->room[n].state == 0)
            {
                cout << "预定成功★房间号码为: " << mgrobj->room[n].number << endl;
                mgrobj->room[n].state = 1;
                mgrobj->customer[mgrobj->i]->set_room_number(mgrobj->room[n].number);
                break;
            }
        }
        break;
    case 4:
        cout << "住房费用总共为: " << day * price4 << "元\n";
        for (n = 60; n < 80; n++)
        {
            if (mgrobj->room[n].state == 0)
            {
                cout << "预定成功★房间号码为: " << mgrobj->room[n].number << endl;
                mgrobj->room[n].state = 1;
                mgrobj->customer[mgrobj->i]->set_room_number(mgrobj->room[n].number);
                break;
            }
        }
        break;
    default:
        cout << "输入有误，请重新输入";
        goto Again006;
    }
    mgrobj->i++; // 住房的顾客数加1
}